<script lang="ts">
export default defineComponent({
  name: 'SvgIcon',
  props: {
    prefix: {
      type: String,
      default: 'icon',
    },
    name: {
      type: String,
      required: true,
    },
  },
  computed: {
    component(): string {
      return this.prefix === 'icon' ? 'svg' : 'i'
    },
    iconName(): string {
      return `#${this.prefix}-${this.name}`
    },
    className(): string {
      if (this.prefix === 'icon') {
        return 'svg-icon'
      } else if (this.prefix === 'iconfont') {
        return 'iconfont icon-' + this.name
      } else {
        return ''
      }
    },
  },
})
</script>

<template>
  <component :is="component" :class="className" aria-hidden="true">
    <use :href="iconName" />
  </component>
</template>



<style scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
.svg-icon:hover {
  fill: var(--primary-color-hover);
}

.svg-external-icon {
  background-color: currentColor;
  mask-size: cover !important;
  display: inline-block;
}
</style>
